/**
 * [OElove] (C)2010-2099 oelove.com Inc. biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/02/15 by OE $
*/
$(function(){
	//显示设置地图窗口
	$(document).on("click", "[f='but_open_setmap_tips']", function(){
		$("#setmap_tips_box").fadeIn(200);
	});
	//关闭设置地图窗口
	$(document).on("click", "[f='but_close_setmap_tips']", function(){
		$("#setmap_tips_box").hide();
	});

	//弹出地图窗口
	$(document).on("click", "[f='pop_open_map']", function(){
		if (_LOGIN_STATUS == 0) {
			_jdLogin();
			return false;
		}
		$_url = _ROOT_PATH+"index.php?m=user&c=map&r="+get_rndnum(8);
		if ($("#setmap_tips_box").length > 0) {
			$("#setmap_tips_box").hide();
		}
		oeShadeBox("pop_map", "ajax", $_url, 800, 510, function(){
			_initOEmap();//回调初始化地图
		});
	});
	
	//搜索地图地址
	$(document).on("click", "[f='but_search_map_location']", function(){
		_searchMap();
	});

	//关闭地图提示
	$(document).on("click", "[f='but_close_maptips']", function(){
		$(this).parent().fadeOut(200);
	});

	//完成地图保存
	$(document).on("click", "[f='but_save_setmap']", function(){
		if (_LOGIN_STATUS == 0) {
			_jdLogin();
			return false;
		}
		$_maplng = $("#maplng").val();
		$_maplat = $("#maplat").val();
		if ($_maplng.length == 0) {
			ToastShow("请先设置地图坐标");
			return false;
		}
		if ($_maplat.length == 0) {
			ToastShow("请先设置地图坐标");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _ROOT_PATH+"index.php?m=user&c=map",
			cache: false,
			data: {
					a:"saveset", maplng:$_maplng, maplat:$_maplat, datatype:"json", r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("pop_map", function(){
						ToastShow("坐标设置成功");
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("保存失败");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});
	});
	
});